<template>
    <Modal
            class-name="vertical-center-modal"
            v-model="modal"
            :width="60"
            :title="head_title">
        <div class="row"  v-if="modal">
            <div class="col-lg-12">
                <div class="card ">
                    <Form ref="formValidate" :model="info" action="javascript:void(0)">
                        <div class="row">
                            <div class="col-md-12">
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">分活动主题</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.title" placeholder="请输入分活动主题"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">地点</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.address" placeholder="请输入地点"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">开始时间</label>
                                        <div class="col-md-9">
                                            <DatePicker
                                                    type="datetime"
                                                    :value='info.start_at'
                                                    format="yyyy-MM-dd HH:mm:ss"
                                                    placeholder="开始时间"
                                                    @on-change='searchSelectTimeDate'></DatePicker>
                                        </div>
                                    </div>
                                </FormItem>
                            </div>
                        </div>
                    </Form>
                </div>
            </div>
        </div>
        <div slot="footer">
            <button class="btn btn-danger" type="button" @click='cancel'>取消</Button>
            <btn-submit class="btn btn-success" type="submit" :p-click="ok">确定</btn-submit>
        </div>
    </Modal>
</template>
<script>
    import serConference from '../../serves/api-conference'
    const setDataDef = {
        parent_id:"",
        title:"",
        address:"",
        start_at:"",
    };
    export default{
        props:{

        },
        data () {
            return {
                modal:false,
                type:'',
                info:{},
            }
        },
        computed:{
            cDate(){
                return [this.info.start_at,this.info.end_at]
            },
            head_title(){
                return this.type == 'edit' ? '编辑分活动':'编辑分活动'
            },
        },
        methods: {
            async handleOpen(data){
                this.$set(this,'type',data._type||'edit');
                this.info = Object.assign({},setDataDef,data);
                this.$set(this,'modal',true);
            },
            cancel () {
                this.$emit('on-change',false);
                this.$set(this,'modal',false);
            },
            searchSelectTimeDate (value) {
                this.$set(this.info,'start_at',value);
            },
            async ok () {
                let url = 'addChild';
                let data = {
                    parent_id:this.info.parent_id,
                    title:this.info.title,
                    start_at:this.info.start_at,
                    address:this.info.address,
                };
                if(this.type=='edit'){
                    delete data.parent_id;
                    data.id = this.info.id;
                    url = 'saveChild';
                }
                let res = await serConference[url](data);
                if(res.code==1){
                    this.$Message.success(res.message);
                    this.$emit('on-change',true);
                    this.$set(this,'modal',false);
                    return true;
                }else{
                    this.$Message.error(res.message);
                    return false;
                }
            },
        },
        components:{
        }
    }
</script>